package com.cloud.bssp.admin.wanda.convert;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cloud.bssp.admin.wanda.dto.PostDTO;
import com.cloud.bssp.admin.wanda.entity.PostDO;
import com.cloud.bssp.util.BeanCopierUtil;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * Description: 职务
 * Create Date: 2021-07-04T19:00:10.249
 * Modified By：<br>
 * Modified Date：<br>
 * Why & What is modified：<br>
 *
 * @author weirx
 * @version 1.0
 */
@Component
public class PostDoConvert {

    /**
     * DtoToDo
     *
     * @param postDTO
     * @return
     */
    public static PostDO dtoToDo(PostDTO postDTO) {
            PostDO postDO = new PostDO();
        BeanCopierUtil.copy(postDTO, postDO);
        return postDO;
    }

    /**
     * DoToDto
     *
     * @param postDO
     * @return
     */
    public static PostDTO doToDto(PostDO postDO) {
            PostDTO postDTO = new PostDTO();
        BeanCopierUtil.copy(postDO, postDTO);
        return postDTO;
    }

    /**
     * Page<DO> to Page<DTO>
     *
     * @param pageDO
     * @return
     */
    public static Page<PostDTO> pageConvert(Page<PostDO> pageDO) {
        List<PostDTO> list = listConvert(pageDO.getRecords());
        Page<PostDTO> page = new Page<>(pageDO.getCurrent(), pageDO.getSize(), pageDO.getTotal());
        page.setRecords(list);
        return page;
    }

    /**
     * list<DO> to list<DTO>
     *
     * @param listDO
     * @return
     */
    public static List<PostDTO> listConvert(List<PostDO> listDO) {
        List<PostDTO> list = new ArrayList<>();
            PostDTO postDTO;
        for (PostDO postDO : listDO) {
                postDTO = new PostDTO();
            BeanCopierUtil.copy(postDO, postDTO);
            list.add(postDTO);
        }
        return list;
    }
}